import React, { Component } from 'react';
import $ from "jquery";
// import {BrowserRouter as Link} from "react-router-dom"; 
import {HashRouter as Router, Route, Link} from 'react-router-dom';
// 
import {connect} from "react-redux";

class ContentWills extends Component {
  componentDidMount(){  
      var that = this;
      $.get("http://localhost:8080/will_playing?",function(res){
          var data = JSON.parse(res).data.films;
          console.log(data);
          that.props.getWillPlayData(data);
      })
  }
  render() {
    return (
      <ul className="content">
          {
            this.props.getData.map(function(item,index){
                var date = new Date(item.premiereAt);
                var month = date.getMonth()+1;
                var day = date.getDate();
                var arr=["星期日","星期一","星期二","星期三","星期四","星期五","星期六"];
                var week = arr[date.getDay()];
                console.log(item);
                return(
                    <li key={index}>
                      <Link to={"/detail/"+item.id}>
                        <img src={item.poster.origin} alt="图片显示异常，请刷新后再试"/>
                        <div className="content_right">
                            <h3><span className="name">{item.name}</span><i className="iconfont">&#xe649;</i></h3>
                            <p className="detail1">{item.intro}</p>
                            <p className="detail2"><span className="time">{month}月{day}日上映</span> <span className="time week">{week}</span></p>
                        </div>
                      </Link>
                  </li>
                )
            })
          }
      </ul>
    );
  }
}

var ContentWill = connect(
  function(state, ownProps) {
    return {
          getData:state.getWillPlayData
    }
  },
  function(dispatch, ownProps) {
   return {
        getWillPlayData:function(data){
            dispatch({
                type:"GETWillPLAYDATA",
                data:data
            })
        }
    }
  }
)(ContentWills);

export default ContentWill;